using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace ElektriSkeemTing
{
    class Questions
    {
        /// <summary>
        /// Structure to hold a Question
        /// </summary>
        public struct Question
        {
            public string ID;
            public string question;
            public string[] answer;
            public string picUrl;
            public int chosenAns;
            public int correct;
        }
        /// <summary>
        /// Shuffles questions
        /// </summary>
        /// <param name="q">Question structure to be shuffled</param>
        /// <returns>A shuffled array of questions</returns>
        public static Question[] Shuffle(Question[] q)
        {
            Random rng = new Random();
            int n = q.Length;
            while (n > 0)
            {
                int k = rng.Next(n);
                n--;
                int m = 4;
                string tempCorrect = q[n].answer[q[n].correct-1];
                while (m > 1)
                {
                    string tempAns = "";
                    int j = rng.Next(m);
                    m--;
                    tempAns = q[n].answer[m];
                    q[n].answer[m] = q[n].answer[j];
                    q[n].answer[j] = tempAns;
                }
                for (int i = 0; i < 4; i++)
                {
                    if (q[n].answer[i] == tempCorrect)
                    {
                        q[n].correct = i+1;
                    }
                }
                Question temp = q[n];
                q[n] = q[k];
                q[k] = temp;
            }
            return q;
        }
    }
}
